/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.PseudoTarget;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.account.accesscontrol.TargetType;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CreateDomain
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  47 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  48 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  50 */     String name = request.getAttribute("name").toLowerCase();
/*  51 */     Map<String, Object> attrs = AdminService.getAttrs(request, true);
/*     */     
/*     */ 
/*  54 */     if (name.indexOf('.') == -1)
/*     */     {
/*  56 */       checkRight(zsc, context, null, Rights.Admin.R_createTopDomain);
/*     */ 
/*     */ 
/*     */     }
/*     */     else
/*     */     {
/*     */ 
/*  63 */       String domainName = name;
/*  64 */       Domain parentDomain = null;
/*  65 */       while (parentDomain == null) {
/*  66 */         int nextDot = domainName.indexOf('.');
/*  67 */         if (nextDot == -1)
/*     */         {
/*  69 */           checkRight(zsc, context, null, Rights.Admin.R_createTopDomain);
/*     */           
/*     */ 
/*  72 */           parentDomain = PseudoTarget.createPseudoDomain(prov);
/*  73 */           break;
/*     */         }
/*  75 */         domainName = domainName.substring(nextDot + 1);
/*  76 */         parentDomain = Provisioning.getInstance().get(Key.DomainBy.name, domainName);
/*     */       }
/*     */       
/*  79 */       checkRight(zsc, context, parentDomain, Rights.Admin.R_createSubDomain);
/*     */     }
/*     */     
/*     */ 
/*  83 */     checkSetAttrsOnCreate(zsc, TargetType.domain, name, attrs);
/*     */     
/*  85 */     Domain domain = prov.createDomain(name, attrs);
/*     */     
/*  87 */     ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "CreateDomain", "name", name }, attrs));
/*     */     
/*     */ 
/*  90 */     Element response = zsc.createElement(AdminConstants.CREATE_DOMAIN_RESPONSE);
/*  91 */     GetDomain.encodeDomain(response, domain);
/*     */     
/*  93 */     return response;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/*  98 */     relatedRights.add(Rights.Admin.R_createTopDomain);
/*  99 */     relatedRights.add(Rights.Admin.R_createSubDomain);
/* 100 */     notes.add(String.format("All attrs provided in the attribute list have to settable by. the authed admin.   You can grant the %s right, which allows setting all attributes on %s, or grant the set attrs right just for the attributes the admin needs to set while creating an entry.", new Object[] { Rights.Admin.R_modifyDomain.getName(), "domain" }));
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/CreateDomain.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */